package org.pz.config;

import lombok.extern.slf4j.Slf4j;
import org.pz.entity.MallResult;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import javax.servlet.http.HttpServletRequest;

/**
 * 全家异常处理器
 * */
@Slf4j
@ControllerAdvice(basePackages = "org.pz")
public class ExceptionConfig {

    /**
     * 拦截所有不知名异常
     * */
    @ExceptionHandler(Exception.class)
    public ResponseEntity<MallResult> exceptionHandler(Exception ex, HttpServletRequest request) {
        log.info("异常信息：", ex);
        return ResponseEntity.status(HttpStatus.OK).body(MallResult.error(StringUtils.isEmpty(ex.getMessage())?"系统内部异常":ex.getMessage()));
    }

}
